package io.github.wslxm.springbootplus2.manage.gc.controller;

import io.github.wslxm.springbootplus2.core.base.controller.BaseController;
import io.github.wslxm.springbootplus2.core.constant.BaseConstant;
import io.github.wslxm.springbootplus2.core.result.Result;
import io.github.wslxm.springbootplus2.manage.gc.model.vo.TableFieldVO;
import io.github.wslxm.springbootplus2.manage.gc.model.vo.TableVO;
import io.github.wslxm.springbootplus2.manage.gc.service.DataBaseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据库操作类/代码生成等处理
 *
 * @author 王松
 * @WX-QQ 1720696548
 * @date 2019/11/20 11:03
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping(BaseConstant.Uri.API_ADMIN + "/gc/dataBase")
@Tag(name = "base--gc--代码生成--查询表数据")
public class DataBaseController extends BaseController<DataBaseService> {


    @Operation(summary = "查询所有表名")
    @GetMapping(value = "/table/list")
    @Parameter(name = "dataSourceId", description = "数据源Id (如果没有选择数据源,默认查询当前项目的数据源一)", required = false, example = "")
    public Result<List<TableVO>> findTable(String dataSourceId) {
        List<TableVO> tables = baseService.findTable(dataSourceId);
        return Result.success(tables);
    }


    @Operation(summary ="查询指定表下所有字段内容")
    @GetMapping(value = "/table/field")
    @Parameters({
            @Parameter(name = "tableName", description = "表名", required = false),
            @Parameter(name = "dataSourceId", description = "数据源Id (如果没有选择数据源,默认查询当前项目的数据源一)", required = false, example = "")
    })
    public Result<List<TableFieldVO>> findTableField(@RequestParam(required = false) String tableName, String dataSourceId) {
        List<TableFieldVO> tableField = baseService.findTableField(tableName, dataSourceId);
        return Result.success(tableField);
    }
}